package top.go2do.common.module;

import javax.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @author xingyuji
 * @date 2025/3/16 17:54
 * @description 用户主表
 */
@Entity
@Table(name = "user", uniqueConstraints = {
        @UniqueConstraint(name = "idx_unique_username", columnNames ={"app_id", "username"}),
        @UniqueConstraint(name = "idx_unique_email", columnNames ={"app_id", "email"}),
        @UniqueConstraint(name = "idx_unique_phone", columnNames ={"app_id", "phone"})
})
@Data
public class UserPO {
    @Id
    @Column(name = "user_id", columnDefinition = "BIGINT UNSIGNED COMMENT '用户ID(雪花算法分布式ID)'")
    private Long userId;

    @Column(name = "app_id", nullable = false, columnDefinition = "VARCHAR(32) COMMENT '所属应用ID'")
    private String appId;

    @Column(name = "username", nullable = false, columnDefinition = "VARCHAR(50) COMMENT '登录名'")
    private String username;

    @Column(name = "password_hash", nullable = false, columnDefinition = "VARCHAR(128) COMMENT '登录密码的密文'")
    private String passwordHash;

    @Column(name = "email", columnDefinition = "VARCHAR(255) COMMENT '邮箱'")
    private String email;

    @Column(name = "phone", columnDefinition = "VARCHAR(20) COMMENT '手机号'")
    private String phone;

    @Column(name = "status", nullable = false, columnDefinition = "TINYINT UNSIGNED DEFAULT 1 COMMENT '1正常,2冻结,3已注销'")
    private Integer status;

    @Column(name = "created_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间'")
    private LocalDateTime createdAt;

    @Column(name = "created_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '创建者'")
    private Long createdBy;

    @Column(name = "updated_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间'")
    private LocalDateTime updatedAt;

    @Column(name = "updated_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '更新者'")
    private Long updatedBy;

    public UserPO(){}
}
